<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div>
  <div fxFlex="70">
    <div fxLayout="row" fxLayoutAlign="center">
      <div fxFlex>This group has <b>{{members.length}}</b> members(s).</div>
      <div style="height: 40px;">
        <button *ngIf="editMode" color="primary" mat-stroked-button (click)="add()">+ Add members</button>
      </div>
    </div>
    <mat-divider *ngIf="isEmpty" style="margin-bottom: 20px;"></mat-divider>
    <ngx-datatable *ngIf="!isEmpty" class="material"
                   [columnMode]="'flex'"
                   [headerHeight]="40"
                   [footerHeight]="40"
                   [rowHeight]="50"
                   [rows]='members'
                   [externalPaging]="true"
                   [count]="page.totalElements"
                   [offset]="page.pageNumber"
                   [limit]="page.size"
                   (page)='setPage($event)'>
      <ngx-datatable-column name="Name" [flexGrow]="4" [cellClass]="'member-name-cell'">
        <ng-template let-row="row" ngx-datatable-cell-template>
          <div class="user-header" fxLayout="row">
            <div class="user-avatar"
                 matBadge="&#8288;"
                 matBadgeSize="small"
                 [ngClass]="(row.enabled && !accountLocked(row)) ? 'user-enabled': (!row.enabled ? 'user-disabled' : accountLocked(row) ? 'user-locked' : '')"
                 [matTooltip]="(row.enabled && !accountLocked(row)) ? 'User enabled': (!row.enabled ? 'User disabled' : accountLocked(row) ? 'User locked' : '')">
              <app-user-avatar [user]="row" [width]="'40'"></app-user-avatar>
            </div>
            <div class="user-information" fxLayout="column">
              <a [routerLink]="userLink(row)">{{row.displayName}}</a>
              <small>{{row.username}}</small>
            </div>
          </div>
        </ng-template>
      </ngx-datatable-column>
      <ngx-datatable-column name="Identity Provider" [flexGrow]="2">
        <ng-template let-row="row" ngx-datatable-cell-template>
          {{row.source}}
        </ng-template>
      </ngx-datatable-column>
      <ngx-datatable-column name="Last login" [flexGrow]="2">
        <ng-template let-row="row" ngx-datatable-cell-template>
          <span *ngIf="(row.loggedAt)">{{row.loggedAt | humanDate}}</span>
          <span *ngIf="!(row.loggedAt)">Never logged in</span>
        </ng-template>
      </ngx-datatable-column>
      <ngx-datatable-column name="Actions" [flexGrow]="1">
        <ng-template let-row="row" ngx-datatable-cell-template>
          <div fxLayout="row" class="gv-table-cell-actions" *ngIf="editMode" >
            <button mat-icon-button (click)="delete(row.id, $event)"><mat-icon matTooltip="Remove member">highlight_off</mat-icon></button>
          </div>
        </ng-template>
      </ngx-datatable-column>
    </ngx-datatable>
  </div>
  <div class="gv-page-description" fxFlex>
    <h3>Group members</h3>
    <div class="gv-page-description-content">
      <p>
        Add or remove users from group to manage them at group level.
      </p>
    </div>
  </div>
</div>

<app-emptystate *ngIf="isEmpty"
                [message]="'Members will appear here'"
                [subMessage]="'No data to display'"
                [icon]="'people'"></app-emptystate>
